using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace LibreriaCommon
{
   public class Mail
    {
       public static void SendMail(string mailFrom,string[] mailTo,string subject,string body,bool isHtml ){

           try
           {
               System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
               System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();

               smtp.Host = ConfigurationSettings.AppSettings.Get("SmtpHost").ToString();
               if (ConfigurationSettings.AppSettings.Get("SmtpRequiereCredenciales").ToString().ToUpper().Equals("SI"))
                   smtp.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings.Get("SmtpUsuario").ToString(),ConfigurationSettings.AppSettings.Get("SmtpPassword").ToString());
               
               if(mailFrom.Trim().Equals(""))
                   correo.From = new System.Net.Mail.MailAddress(ConfigurationSettings.AppSettings.Get("SmtpFrom").ToString());
               else
                correo.From = new System.Net.Mail.MailAddress(mailFrom);
           
               for (int i = 0; i < mailTo.Length;i++)
                   correo.To.Add(mailTo[i]);
                           
               correo.Subject = subject;
               correo.Body = body;
               correo.IsBodyHtml = isHtml;
               correo.Priority = System.Net.Mail.MailPriority.Normal;
               smtp.Send(correo);
             
           }
           catch (Exception ex) {

               throw new MailException(ex);
           
           }

       }

    }
}
